package sn.gandal.mobile.kalpet.activities;

import java.util.Calendar;

import android.app.Application;

public class KalpetApplication extends Application {
	
	public static String userName;
	public static String password;
	public static boolean authenticated;
	public static long sessionBegin; //en millisecondes
	public static long sessionExpire;
	private static final long DUREE_SESSION=60000;//10mn duree la session = 600000
	
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		userName="";
		password="";
		authenticated=false;
		sessionBegin= Calendar.getInstance().getTimeInMillis();
		sessionExpire=sessionBegin + DUREE_SESSION; 
		
	}

	public static String getUserName() {
		return userName;
	}

	public static void setUserName(String userName) {
		KalpetApplication.userName = userName;
	}

	public static String getPassword() {
		return password;
	}

	public static void setPassword(String password) {
		KalpetApplication.password = password;
	}

	public static boolean isAuthenticated() {
		if(!isSesionValide())
			return false;
		return authenticated;
		
	}

	public static boolean isSesionValide() {
		if(! authenticated || sessionExpire - sessionBegin > DUREE_SESSION){
			return false;
		}
		return true;
		
	}

	public static void setAuthenticated(boolean authenticated) {
		KalpetApplication.authenticated = authenticated;
		//sessionBegin= Calendar.getInstance().getTimeInMillis();
		//sessionExpire=sessionBegin + DUREE_SESSION; 
	}
	


}
